package com.ruoyi.mes.utils;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mes.domain.*;
import com.ruoyi.mes.mapper.*;
import com.ruoyi.mes.vo.product.BomMtrVo;
import com.ruoyi.mes.vo.product.ProOrderVo;
import com.ruoyi.mes.vo.product.ProTecVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 自定义判重工具类
 */


public class RepeatUtils {

    /**
     * 工序Id判重
     * @param proceInfoList
     * @return
     */
    public  static boolean isProceIdRepeat(List<ProceInfo> proceInfoList){
        long original =proceInfoList.size();
        long cout =proceInfoList.stream()// 将List集合转换为Stream流
                .map(ProceInfo::getId) // 获取属性值
                .distinct()// 去除重复元素
                .count();// 统计元素数量
        return cout != original;// 如果元素数量不等于List的大小，则说明存在重复
    }


    /**
     * 工序顺序判重
     * @param proceInfoList
     * @return
     */
    public static boolean isProceSequeRepeat(List<ProceInfo> proceInfoList){
        long cout =proceInfoList.stream()// 将List集合转换为Stream流
                .map(ProceInfo::getProceSeque) // 获取属性值
                .distinct()// 去除重复元素
                .count();// 统计元素数量
        return cout != proceInfoList.size();// 如果元素数量不等于List的大小，则说明存在重复
    }

    /**
     * 工艺编码判重
     * @param proTecVo
     * @return
     */
    public  static boolean isTecCodeRepeat(ProTecMapper proTecMapper ,ProTecVo proTecVo){
        List<ProTec> proTecs = proTecMapper.selectProTecListByTecCode(proTecVo.getTecCode());
        if (proTecs.size() != 0){
            return true;
        }
        return false;
    }

    /**
     * Bom编码判重
     * @param proBomMapper
     * @param bomMtrVo
     * @return
     */
    public static boolean isBomCodeRepeat(ProBomMapper proBomMapper,BomMtrVo bomMtrVo){
        //判断Bom编码是否重复
        ProBom bom = new ProBom();
        bom.setBomCode(bomMtrVo.getBomCode());
        List<ProBom> boms = proBomMapper.selectProBomList(bom);
        if (boms.size() != 0) {
            return true;
        }
        return false;
    }


    /**
     * 产品订单编码判重
     * @param proOrderMapper
     * @param proOrderVo
     * @return
     */
    public static boolean isOrderNumberRepeat(ProOrderMapper proOrderMapper , ProOrderVo proOrderVo){
        if(proOrderVo.getOrderNumber() == "" || proOrderVo.getOrderNumber() == null) {
            return false;
        }
        //判断产品订单编码是否重复
        ProOrder proOrder = new ProOrder();
        proOrder.setOrderNumber(proOrderVo.getOrderNumber());
        List<ProOrder> proOrders = proOrderMapper.selectProOrderList(proOrder);
        if (proOrders.size() != 0) {
            return true;
        }
        return false;
    }

    /**
     * 产品订单 -产品判重
     * @param proInfoList
     * @return
     */
    public static boolean isProductRepeat(List<ProInfo> proInfoList){
        long cout =proInfoList.stream()// 将List集合转换为Stream流
                .map(ProInfo::getId) // 获取属性值
                .distinct()// 去除重复元素
                .count();// 统计元素数量
        return cout != proInfoList.size();// 如果元素数量不等于List的大小，则说明存在重复
    }


    /**
     * 库位编码判重
     * @param locatorInfoMapper
     * @param locatorInfo
     * @return
     */
    public static boolean isLocatorCoderRepeat(LocatorInfoMapper locatorInfoMapper, LocatorInfo locatorInfo){
        if(locatorInfo.getCode() == "" || locatorInfo.getCode() == null) {
            return false;
        }
        //判断产品订单编码是否重复
        LocatorInfo info = new LocatorInfo();
        info.setCode(locatorInfo.getCode());
        List<LocatorInfo> list = locatorInfoMapper.selectLocatorInfoList(info);
        if (list.size() != 0) {
            return true;
        }
        return false;
    }

    /**
     * 设备编码判重
     * @param deviceMapper
     * @param device
     * @return
     */
    public static boolean isDeviceCodeRepeat(DeviceMapper deviceMapper, Device device) {
        if(device.getDeviceCode() == "" || device.getDeviceCode() == null) {
            return false;
        }
        //判断产品订单编码是否重复
        Device info = new Device();
        info.setDeviceCode(device.getDeviceCode());
        List<Device> list = deviceMapper.selectDeviceList(info);
        if (list.size() != 0) {
            return true;
        }
        return false;
    }
}
